package com.jqb.spring;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class SecurityHandler implements InvocationHandler {

	private Object targetObject;
	
	public Object newProxy(Object targetObject){
		this.targetObject=targetObject;
		return Proxy.newProxyInstance(targetObject.getClass().getClassLoader(),
				targetObject.getClass().getInterfaces(), this);
	}
	
	public Object invoke(Object proxy, Method method, Object[] args)
			throws Throwable {
//		System.out.println("method.name="+method.getName());
//		System.out.println("method="+method);
		//进行统一安全性检查
		checkSecurity();
		Object result=null;
		try{
			result=method.invoke(this.targetObject,args);
		}catch(Exception e){
			e.printStackTrace();
			throw new java.lang.RuntimeException(e);
		}
		return result;
	}
	//安全性检查方法
	public void checkSecurity() {
		System.out.println("----checkSecurity");
	}
}
